package com.ruoyi.security.service.impl;

import cn.hutool.core.util.IdUtil;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.SecurityUtils;
import com.ruoyi.security.domain.AfSafetyInspection;
import com.ruoyi.security.mapper.AfSafetyInspectionMapper;
import com.ruoyi.security.service.IAfSafetyInspectionService;
import com.ruoyi.system.api.LinkFileServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 安全检查Service业务层处理
 *
 * @author cjie
 * @date 2021-12-08
 */
@Service
public class AfSafetyInspectionServiceImpl extends LinkFileServiceImpl implements IAfSafetyInspectionService {
    @Autowired
    private AfSafetyInspectionMapper afSafetyInspectionMapper;

    /**
     * 查询安全检查
     *
     * @param id 安全检查ID
     * @return 安全检查
     */
    @Override
    public AfSafetyInspection selectAfSafetyInspectionById(String id) {
        AfSafetyInspection afSafetyInspection = afSafetyInspectionMapper.selectAfSafetyInspectionById(id);
        afSafetyInspection.setFileList(getFileList(id));
        return afSafetyInspection;
    }

    /**
     * 查询安全检查列表
     *
     * @param afSafetyInspection 安全检查
     * @return 安全检查
     */
    @Override
    public List<AfSafetyInspection> selectAfSafetyInspectionList(AfSafetyInspection afSafetyInspection) {
        return afSafetyInspectionMapper.selectAfSafetyInspectionList(afSafetyInspection);
    }

    /**
     * 新增安全检查
     *
     * @param afSafetyInspection 安全检查
     * @return 结果
     */
    @Override
    public int insertAfSafetyInspection(AfSafetyInspection afSafetyInspection) {
        afSafetyInspection.setId(IdUtil.getSnowflake(0, 0).nextIdStr());
        afSafetyInspection.setCreateTime(DateUtils.getNowDate());
        afSafetyInspection.setCreateBy(SecurityUtils.getUsername());
        linkFile(afSafetyInspection.getFileIdList(), afSafetyInspection.getId());
        return afSafetyInspectionMapper.insertAfSafetyInspection(afSafetyInspection);
    }

    /**
     * 修改安全检查
     *
     * @param afSafetyInspection 安全检查
     * @return 结果
     */
    @Override
    public int updateAfSafetyInspection(AfSafetyInspection afSafetyInspection) {
        afSafetyInspection.setUpdateTime(DateUtils.getNowDate());
        afSafetyInspection.setUpdateBy(SecurityUtils.getUsername());
        return afSafetyInspectionMapper.updateAfSafetyInspection(afSafetyInspection);
    }

    /**
     * 批量删除安全检查
     *
     * @param ids 需要删除的安全检查ID
     * @return 结果
     */
    @Override
    public int deleteAfSafetyInspectionByIds(String[] ids) {
        deleteLinkFile(ids);
        return afSafetyInspectionMapper.deleteAfSafetyInspectionByIds(ids);
    }

    /**
     * 删除安全检查信息
     *
     * @param id 安全检查ID
     * @return 结果
     */
    @Override
    public int deleteAfSafetyInspectionById(String id) {
        return afSafetyInspectionMapper.deleteAfSafetyInspectionById(id);
    }
}
